﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using System.Data.Common;
using Husb.Data;
using Husb.DataUtil;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Caching;

using CentralOffice.PublicAffair.Data;

using PostTable = CentralOffice.PublicAffair.Data.PostDataSet.PostsDataTable;
using PostRow = CentralOffice.PublicAffair.Data.PostDataSet.PostsRow;

namespace CentralOffice.PublicAffair.DataAccess
{
    public class PostDataAdapter : DataAccessAdapter<PostDataSet, PostTable, PostRow>
    {
        private const string UpdateStatusStoredProc = "Tasks.Tasks_UpdateTaskStatus";
        private const string SelectTaskAttendmentsByIdStoredProc = "Tasks.Tasks_SelectTaskAttendmentsById";
        private const string SelectTaskByEmployeeStoredProc = "Tasks.Tasks_SelectTaskByEmployee";
        public PostDataAdapter()
        {
            this.TableName = "Posts";

            GetAllStoredProc = "PublicAffairs.Posts_SelectPostsAll";
            InsertStoredProc = "PublicAffairs.Posts_InsertPost";
            UpdateStoredProc = "PublicAffairs.Posts_UpdatePost";
            DeleteStoredProc = "PublicAffairs.Posts_DeletePost";

            GetByIdStoredProc     = "PublicAffairs.Posts_SelectPost";
            GetByNameStoredProc   = "";
            GetPagedStoredProc    = "PublicAffairs.Posts_SelectPostsPaged";
            GetRowCountStoredProc = "PublicAffairs.Posts_SelectPostsRowCount";

            FindStoredProc = "PublicAffairs.Posts_SelectPostsDynamic";

            LogicalDeleteStoredProc = "PublicAffairs.Posts_DeletePost";
        }

        protected override void PopulateInsertParameters(Database db, DbCommand cmd)
        {
            db.AddInParameter(cmd, "Id", DbType.Guid, "Id", DataRowVersion.Current);
            db.AddInParameter(cmd, "Name", DbType.AnsiString, "Name", DataRowVersion.Current);
            db.AddInParameter(cmd, "Category", DbType.Int32, "Category", DataRowVersion.Current);
            db.AddInParameter(cmd, "Author", DbType.AnsiString, "Author", DataRowVersion.Current);
            db.AddInParameter(cmd, "Accepter", DbType.AnsiString, "Accepter", DataRowVersion.Current);
            db.AddInParameter(cmd, "ContentText", DbType.String, "ContentText", DataRowVersion.Current);
            db.AddInParameter(cmd, "Attachments", DbType.String, "Attachments", DataRowVersion.Current);
            db.AddInParameter(cmd, "Status", DbType.Int32, "Status", DataRowVersion.Current);
            db.AddInParameter(cmd, "IsDeleted", DbType.Boolean, "IsDeleted", DataRowVersion.Current);
            db.AddInParameter(cmd, "IsActive", DbType.Boolean, "IsActive", DataRowVersion.Current);
            db.AddInParameter(cmd, "CreatedTime", DbType.DateTime, "CreatedTime", DataRowVersion.Current);
            db.AddInParameter(cmd, "CreatedBy", DbType.Guid, "CreatedBy", DataRowVersion.Current);
            db.AddInParameter(cmd, "ModifiedTime", DbType.DateTime, "ModifiedTime", DataRowVersion.Current);
            db.AddInParameter(cmd, "LastModifiedBy", DbType.Guid, "LastModifiedBy", DataRowVersion.Current);
            db.AddInParameter(cmd, "Version", DbType.Int32, "Version", DataRowVersion.Current);
            db.AddInParameter(cmd, "Description", DbType.String, "Description", DataRowVersion.Current);
        }
    }
}


//lblId.Text = post.Id;
//lblName.Text = post.Name;
//lblCategory.Text = post.Category;
//lblAuthor.Text = post.Author;
//lblAccepter.Text = post.Accepter;
//lblContentText.Text = post.ContentText;
//lblAttachments.Text = post.Attachments;
//lblStatus.Text = post.Status;
//lblIsDeleted.Text = post.IsDeleted;
//lblIsActive.Text = post.IsActive;
//lblCreatedTime.Text = post.CreatedTime;
//lblCreatedBy.Text = post.CreatedBy;
//lblModifiedTime.Text = post.ModifiedTime;
//lblLastModifiedBy.Text = post.LastModifiedBy;
//lblVersion.Text = post.Version;
//lblDescription.Text = post.Description;

//txtId.Text = post.Id;
//txtName.Text = post.Name;
//txtCategory.Text = post.Category;
//txtAuthor.Text = post.Author;
//txtAccepter.Text = post.Accepter;
//txtContentText.Text = post.ContentText;
//txtAttachments.Text = post.Attachments;
//txtStatus.Text = post.Status;
//txtIsDeleted.Text = post.IsDeleted;
//txtIsActive.Text = post.IsActive;
//txtCreatedTime.Text = post.CreatedTime;
//txtCreatedBy.Text = post.CreatedBy;
//txtModifiedTime.Text = post.ModifiedTime;
//txtLastModifiedBy.Text = post.LastModifiedBy;
//txtVersion.Text = post.Version;
//txtDescription.Text = post.Description;

//post.Id = txtId.Text;
//post.Name = txtName.Text;
//post.Category = txtCategory.Text;
//post.Author = txtAuthor.Text;
//post.Accepter = txtAccepter.Text;
//post.ContentText = txtContentText.Text;
//post.Attachments = txtAttachments.Text;
//post.Status = txtStatus.Text;
//post.IsDeleted = txtIsDeleted.Text;
//post.IsActive = txtIsActive.Text;
//post.CreatedTime = txtCreatedTime.Text;
//post.CreatedBy = txtCreatedBy.Text;
//post.ModifiedTime = txtModifiedTime.Text;
//post.LastModifiedBy = txtLastModifiedBy.Text;
//post.Version = txtVersion.Text;
//post.Description = txtDescription.Text;